﻿@model Zj.CourseManage.DTO.Common.Pagination.PaginatedList<Zj.CourseManage.Domain.Core.Student>
@{
    ViewData["Title"] = "学生列表";
}
<h2>学生列表</h2>
<a href="/Students/Create" class="text-success">添加</a>
<br />
<article>
    <form class="form-inline" role="form">
        <div class="form-group">
            <label for="searchString">姓名：</label>
            <input type="text" class="form-control" id="searchString" name="searchString" placeholder="search string" value="@ViewData["searchString"]">
        </div>
        <button type="submit" class="btn btn-default">搜索</button>
        <a asp-action="index">显示所有</a>
    </form>
    <br />
    <table class="table table-hover table-bordered table-condensed table-responsive table-striped">
        <tr>
            <th width="70"><a asp-route-sortName="@ViewData["sortName"]" asp-route-searchString="@ViewData["searchString"]">姓名</a> </th>
            <th><a asp-route-sortName="@ViewData["sortBirthday"]" asp-route-searchString="@ViewData["searchString"]">出身日期</a></th>
            <th width="670">介绍</th>
            <th width="170">操作</th>
        </tr>
        @foreach (var stu in Model)
        {
            <tr>
                <td>@stu.Name</td>
                <td>@stu.Birthday.ToString("yyyy-MM-dd")</td>
                <td>@stu.Introduction</td>
                <td>
                    <div class="btn-group" role="group" aria-label="...">
                        <button type="button" class="btn btn-primary" onclick="location.href='/Students/Edit/@stu.Id'">修改</button>
                        <button type="button" class="btn btn-danger" onclick="del(@stu.Id)">删除</button>
                    </div>
                </td>
            </tr>
        }
    </table>
    @{
        var previousDisable = Model.HasPrevious?"":"disabled";
        var nextDisable = Model.HasNext?"":"disabled";
        var previous = (int)ViewData["pageIndex"] - 1;
        var next= (int)ViewData["pageIndex"] + 1;
    }
    <nav aria-label="...">
        <ul class="pager">
            <li><a asp-route-pageIndex="@previous"  asp-route-searchString="@ViewData["searchString"]"  class="btn btn-default @previousDisable">Previous</a></li>
            <li>@ViewData["pageIndex"]</li>
            <li><a asp-route-pageIndex="@next"  asp-route-searchString="@ViewData["searchString"]" asp-action="Index" class="btn btn-default @nextDisable">Next</a></li>
        </ul>
    </nav>
</article>
@section Scripts{
    <script>
        function del(id) {
            if (confirm("确认删除吗？")) {
                $.ajax({
                    type: 'get',
                    url: '/Students/Delete/' + id,
                    success: function (data) {
                        location.reload()
                    }
                });
            }
        }
    </script>
}